Skip to content

util: fix -Wshorten-64-to-32 warnings#12534

Closed
catenacyber wants to merge 1 commit intoOISF:masterfrom
catenacyber:warnint-64to32-6186-v20
Closed

util: fix -Wshorten-64-to-32 warnings#12534
catenacyber wants to merge 1 commit intoOISF:masterfrom
catenacyber:warnint-64to32-6186-v20

Conversation

@catenacyber
Copy link
Contributor

Link to redmine ticket:
https://redmine.openinfosecfoundation.org/issues/6186

Describe changes:

  • fix -Wshorten-64-to-32 warnings for some files : util

One commit of #9840
#12481 improved after review

Still to do afterwards :

  • detect
  • CI check

@codecov
Copy link

codecov bot commented Feb 6, 2025

Codecov Report

Attention: Patch coverage is 71.92982% with 32 lines in your changes missing coverage. Please review.

Project coverage is 80.69%. Comparing base (d4330ef) to head (d66110f).
Report is 52 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #12534   +/-   ##
=======================================
  Coverage   80.68%   80.69%           
=======================================
  Files         925      925           
  Lines      258914   258944   +30     
=======================================
+ Hits       208914   208943   +29     
- Misses      50000    50001    +1     
Flag Coverage Δ
fuzzcorpus 56.88% <50.00%> (+0.05%) ⬆️
livemode 19.40% <20.17%> (-0.01%) ⬇️
pcap 44.17% <46.49%> (-0.03%) ⬇️
suricata-verify 63.39% <50.87%> (-0.01%) ⬇️
unittests 58.38% <44.73%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 24636

char *sep = strchr(lnode->val, '-');
char *end;
a = strtoul(lnode->val, &end, 10);
a = (int)strtoul(lnode->val, &end, 10);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit odd, downcasting strtoul to int... should we just use atoi? Or one of our parsing wrappers perhaps

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying StringParseUint32

if (data_offset < sbblen) {
*data = region->buf;
*data_len = sbblen - data_offset;
DEBUG_VALIDATE_BUG_ON(sbblen - data_offset > UINT32_MAX);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these checks are a bit ugly, would it make sense to have a dedicated macro to hide the check details?

untested and with a poor name, but something like

U32_SUB_CHECK(sbblen, data_offset);

#define U32_SUB_CHECK(a,b) \
    DEBUG_VALIDATE_BUG_ON((a) - (b) > UINT32_MAX); \
    (a) - (b)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improving some go these checks by making data_offset a u32 in the first place

Copy link
Member

@victorjulien victorjulien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline

@catenacyber
Copy link
Contributor Author

Next in #12624

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants